/* -*- Mode:Prolog; coding:ISO-8859-1; -*- */

:-if(current_prolog_flag(dialect, sicstus)).
:- use_module(library(file_systems)).
:- ensure_loaded(sicstus_support).
:-endif.

:-if(current_prolog_flag(dialect, yap)).
:- use_module(library(system)).
directory_exists(X) :- file_exists(X).
:-endif.

:- use_module(library(lists)).



file_to_list(F,List) :- 
   open(F,read,Stream), set_input(Stream), 
   inquire([],R), % gather terms from file
   reverse(R,List),
   current_input(Stream), close(Stream), set_input(user).


inquire(IN,OUT):-
   read(Data), 
   (Data == end_of_file ->   % done
      OUT = IN 
        ;    % more
      inquire([Data|IN],OUT) ) . 
      

list_to_file(List, F) :- 
   open(F,write,Stream), set_output(Stream), 
   to_current_output(List), % gather terms from file
   flush_output,
   current_output(Stream), close(Stream), set_output(user).


to_current_output(List):-
   flush_output,     
   (List == [] ->   % done
      true
        ;    % more
      (List =   [Data|In],
      portray_clause(Data),
      to_current_output(In) )) . 

delete_output_file :-
        file_exists('../temp/output'), !,
        delete_file('../temp/output').
delete_output_file.

open_output_file(Stream) :-
   open('../temp/output',append,Stream).

wof(Output, Stream) :-
   set_output(Stream),
   portray_list(Output),
   set_output(user).

close_output_file(Stream) :-
   close(Stream).
   